// wglquark.cpp
//

#include "config.h"
#include "wgl/wglquark.hpp"

using namespace wgl;



// Quark::Quark
//
Quark::Quark ( const std::string &name )
{
  auto it = quarks_by_name.find(name);
  if (it == quarks_by_name.end())
    {
      value_ = ++value_counter;
      auto r = quarks_by_name.try_emplace(name, value_);
      WGL_ASSERT(r.second);
      auto r2 = quarks_by_id.try_emplace(value_, r.first->first);
      WGL_ASSERT(r2.second);
    }
  else
    {
      value_ = it->second;
    }
}



// Quark::name
//
const std::string &Quark::name () const
{
  auto it = quarks_by_id.find(value_);
  WGL_ASSERT(it != quarks_by_id.end());
  return it->second;
}
